// @charset "utf-8";
/**
 * 短期分析画图
 */
define(function(require, exports, module) {

	var dqfxChart = {
		isShowSh: false,
		render0: function(chartData, param) {
			var self = this;
			self.renderChart(chartData, param);
		},
		render: function(chartData, param) {
			var self = this;
			var zdftype = {
				'1' : '3日涨幅大于10%',
				'2' : '3日涨幅大于20%',
				'3' : '3日涨幅大于30%',
				'4' : '3日跌幅大于10%',
				'5' : '3日跌幅大于20%',
				'6' : '3日跌幅大于30%'
			};
			var $chartDom = $('#view_div_dqfxchart');
			var xAxis = chartData.xAxisDate,
				zfData = chartData.zfData,
				dfData = chartData.dfData,
				shData = chartData.shData;

			var zfLegend = zdftype[param['zf']];
			var dfLegend = zdftype[param['df']];

			var tickInterval = Math.ceil(xAxis.length / 10);

			var yellowColor = '#efefef';
			if (commonMethod.thsSkin == 'white') {
				yellowColor = '#e08900';
			}
			var chartOption = {
				credits: {
					enabled: false
				},
				title: {
					text: ''
				},
				chart: {
					backgroundColor: 'rgba(0,0,0,0)',
					style: {
						fontFamily: 'Microsoft yahei'
					},
					marginTop: 36,
					marginLeft: 40,
					events : {
						click : function () {
							$('.view_ul_selectbox').addClass('hide');
						}
					}
				},
				series: [{
					name: zfLegend,
					type: 'line',
					color: '#ff3232',
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								fillColor: '#ff3232',
								radius: 2,
								lineColor: 'rgba(255, 255, 255, 1)',
								lineWidthPlus: 1
							}
						}
					},
					data: zfData,
					point: {
						events: {
							mouseOver: function() {
								$('.view_i_dqfxzf').text(this.y);
							}
						}
					}
				}, {
					name: dfLegend,
					type: 'line',
					color: '#00e600',
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								fillColor: '#2aaa2a',
								radius: 2,
								lineColor: 'rgba(255, 255, 255, 1)',
								lineWidthPlus: 1
							}
						}
					},
					data: dfData,
					point: {
						events: {
							mouseOver: function(e) {
								$('.view_i_dqfxdf').text(this.y);
							}

						}
					}
				},{
					name: '上证',
					type: 'line',
					color: yellowColor,
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								fillColor: '#efefef',
								radius: 2,
								lineColor: 'rgba(200, 200, 200, 1)',
								lineWidthPlus: 1
							}
						}
					},
					data: shData,
					point: {
						events: {
							mouseOver: function() {
								$('.dqfx-legend:eq(2)').text(this.y);
							}
						}
					},
					visible : self.isShowSh,
					yAxis: 1
				}],
				plotOptions: {
					series: {
						stickyTracking: false
						// events: {
						// 	legendItemClick: function () {
						// 		if (this.name != '上证') {
						// 			return false;
						// 		}
						// 	}
						// }
					},
					line: {
						states: {
							hover: {
								lineWidthPlus: 0
							}
						}
					}
				},
				xAxis: {
					lineWidth: 1,
					tickLength: 4,
					lineColor: '#808080',
					tickColor: '#808080',
					tickInterval : tickInterval,
					title: {
						text: ''
					},
					categories: xAxis,
					gridLineWidth: 0,
					labels: {
						align: 'center',
						rotation: 0,
						style: {
							color: '#afafaf'
						}
					},
					showLastLabel: true,
					tickmarkPlacement: 'on',
					startOnTick: true
				},
				yAxis: [{
					allowDecimals: false,
					lineWidth: 1,
					tickColor: '#808080',
					tickPosition: 'outside',
					gridLineWidth: 0,
					tickLength: 4,
					tickWidth: 1,
					title: {
						text: ''
					},
					lineColor: '#808080',
					labels: {
						style: {
							color: '#afafaf'
						},
						x: -7
					},
					min: 0
				}, {
					allowDecimals: false,
					lineWidth: 1,
					tickColor: '#808080',
					tickPosition: 'outside',
					gridLineWidth: 0,
					tickLength: 4,
					tickWidth: 1,
					title: {
						text: ''
					},
					lineColor: '#808080',
					labels: {
						style: {
							color: '#afafaf'
						},
						x: 7,
						format: '{value}'
					},
					opposite: true
				}],
				legend: {
					enabled: false
				},
				tooltip: {
					shared: true,
					enabled: true,
					style: {
						color: '#acb8aa',
						padding: 2
					},
					hideDelay: 10,
					backgroundColor: '#410080',
					borderWidth: 0,
					crosshairs: [{
						width: 1,
						color: '#afafaf'
					}],
					formatter: function() {
						return this.x;
					},
					positioner: function(labelWidth, labelHeight, point) {
						var x = point.plotX + 42 - parseInt(labelWidth / 1);
						return {
							x: x,
							y: $('#view_div_dqfxchart').height() - 37
						};
					}
				}
			};
			$chartDom.highcharts(chartOption);
			this.dqfxHighcahrts = $chartDom.highcharts();
		},
		dqfxHighcahrts: null,
		reflowChart: function() {
			if (this.dqfxHighcahrts != null) {
				this.dqfxHighcahrts.reflow();
			}
		}
	};

	module.exports = dqfxChart;
});